package com.group.service.impl;

import com.forms.platform.group.dao.MemberDao;
import com.group.bean.*;
import com.group.constants.CodeConstants;
import com.group.dao.GroupDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class MemberServiceImpl {

	
	@Autowired
	private GroupDao groupDao;
	
	
	@Autowired
	private MemberDao memberDao;
	
	/**
	 * 加入团
	 * @param groupId
	 * @return
	 */
	public ResponseMessage joinGroup(MemberJoinGroupReq memberJoinGroupReq) {
		GroupInfo groupInfo = groupDao.findGroupById(memberJoinGroupReq.getGroupId());
		if(null == groupInfo) {
			return new ResponseMessage(CodeConstants.CODE_NOT_FOUND_GROUP,"未查询到该团",null);
		}
		Member member =groupDao.findGroupMemberByPhone(memberJoinGroupReq.getPhone());
		
		if(null!= member) {
			return new ResponseMessage(CodeConstants.HAVE_JOIN_GROUP,"已经加入该团",null);
		}
		memberDao.joinGroup(memberJoinGroupReq);
		return new ResponseMessage(CodeConstants.CODE_SUCCESS,"加入成功",groupInfo);
	}
	
	/**
	 * 居民添加商品
	 * @param 
	 * @return
	 */
	public ResponseMessage memberAddGoods(Goods goods) {
		memberGoodsDao.addGoods(goods);
		return new ResponseMessage(CodeConstants.CODE_SUCCESS,"添加成功",null);
	}
}
